var FPSCounter = function () {
    this.times = [];
};
 
FPSCounter.prototype = {
    tick: function () {
        var times = this.times,
            seconds;
 
        times.unshift(+new Date());
 
        if ( times.length > this.span + 1 ) {
            times.pop(); // ditch the oldest time
            seconds = (times[0] - times[times.length - 1]) / 1000;
            return Math.round(this.span / seconds);
        } else {
            return null;
        }
    },
 
    span: 20
};